<template>
  <el-card class="box-card1">
    <div class="container-out" :style="{height: slideFlag?'386px':'660px'}">
      <div class="container-in" :style="{'right':-scrollBarWidth+'px'}">
        <el-timeline class="timeline">
          <el-timeline-item v-for="item in news" :key="item.id" :timestamp="item.showtime" placement="top">
            <el-card :body-style="{padding: '12px'}" shadow="never" class="box-card2">
              <h4 class="title">{{item.title}}</h4>
              <p class="digest">{{item.digest}}</p>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </div>
    </div>
  </el-card>
</template>

<script>
import axios from 'axios'

export default {
  name: "News",
  props: {
    slideFlag: Boolean
  },
  data() {
    return {
      scrollBarWidth: 15,
      news: []
    }
  },
  mounted() {
    window.ipcRenderer.sendSync('zoomFactor', null,
        (zoomFactor) => this.scrollBarWidth = this.scrollBarWidth / zoomFactor)
    this.getNews()
    setInterval(() => {
      this.getNews()
    }, 1000 * 120)
  },
  methods: {
    getNews() {
      const url = 'https://newsinfo.eastmoney.com/kuaixun/v2/api/list?column=102&limit=20&p=1'
      axios.get(url).then((data) => {
        const result = data.data.news
        this.news = result
      })
    }
  }
}
</script>

<style scoped>
.box-card1 {
  width: 400px;
  height: 700px;
  border: none;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.9);
}
.box-card2 {
  border: none;
  background-color: rgba(255, 255, 255, 0.9);
}
:deep(.el-timeline-item__timestamp) {
 color: white;
}
.container-out {
  height: 660px;
  position: relative;
  overflow: hidden;
  transition: height 2s;
}
.container-in {
  position: absolute;
  left: 0;
  top: 0;
  right: -15px;
  bottom: 0;
  overflow-x: hidden;
  overflow-y: scroll;
}
.timeline {
  padding-left: 1px;
}
.title {
  margin: 5px 0;
  font-size: 16px;
}
.digest {
  margin: 10px 0 0 0;
  text-align: left;
  text-indent: 20px;
  font-size: 16px;
}
</style>